package com.leancloud.circle.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.leancloud.circle.R;
import com.leancloud.circle.bean.CollectionBean;

import java.util.Date;

import tech.com.commoncore.manager.GlideManager;
import tech.com.commoncore.utils.DateUtil;

import static tech.com.commoncore.utils.DateUtil.FORMAT_55;

public class CollectionAdapter extends BaseQuickAdapter<CollectionBean, BaseViewHolder> {

    public CollectionAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final CollectionBean item) {

        String nike = item.getUser().getUser_nickname();
        String headUrl = item.getUser().getAvatar();
        String date = DateUtil.formatDate(new Date(item.getCreate_time()), FORMAT_55);
        String userId = String.valueOf(item.getId());
        String content = item.getTitle();

        ImageView head = helper.itemView.findViewById(R.id.circle_item_head_image);
        GlideManager.loadRoundImg(headUrl, head);
        final TextView attentionTx = helper.itemView.findViewById(R.id.circle_item_attention_tx);

        helper.setText(R.id.circle_item_name_tx, nike);
        helper.setText(R.id.circle_item_date_tx, date);
        helper.setText(R.id.circle_item_content_tx, content);

        helper.itemView.findViewById(R.id.circle_item_remove_tx).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                CircleGlobal.getCircleImp().removeCollection(UserGlobal.getCurrentUser().getToken(), item.getId(), new CircleBack() {
//                    @Override
//                    public void onBack(Object o, String err) {
//                        if (err == null) {
//                            remove(helper.getLayoutPosition());
//                        }
//                    }
//                });
            }
        });
    }
}
